<template>
	<view class="list">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:down="downOption" :up="upOption">
			<view class="list-item"  v-for="(item, index) in  list" :key="index">
				<view class="goods" @click="openPage('/pages/pintuan/detail', {id: item.id, type: item.type})">
					<view class="img">
						<image :src="item.pict_url"></image>
					</view>
					<view class="content">
						<view class="title two-line">
							<text class="num">{{item.groupon_num}}人团</text>
							{{item.short_title}}
						</view>
						<view class="price">
							<price :price="item.groupon_price"></price>
							<text class="old-price">¥{{item.original_price}}</text>
						</view>
						<view class="bottom">
							<view style="flex: 1;display: flex;flex-direction: row;">
								<view class="imgs" v-if="item.groupon">
									<image v-for="(user, uindex) in item.groupon.groupon_user" :key="uindex" :src="user.avatar"></image>
								</view>
								<view class="text" v-if="item.sales">{{item.sales}}人已购买</view>
							</view>
							
							<view class="invite">马上团</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import price from "../../components/price.vue"
	export default {
		components: {
			price
		},
		mixins: [MescrollMixin],
		data() {
			return {
				type: 5,
				pagination: {
					auto: false,
					page: 1,
					pageSize: 20,
					total: 0,
				},
				loadStatus: 'loadmore',
				upOption: {
					auto: false,
					page: {
						size: 20 // 每页数据的数量,默认10
					},
					empty: {
						tip: '暂无相关数据'
					},
					textNoMore: "没有更多数据了"
				},
				list: [],
			}
		},
		methods: {
			openPage(path, params) {
				this.$u.route({
					url: path,
					params
				})
			},
			getData(page) {
				let that = this;
				this.$u.api.goodsList({
					page,
					pageSize: this.pagination.pageSize,
					type: this.type,
					classify_id: this.classifyId,
					groupon: 1
				}).then(res => {
					that.mescroll.endByPage(res.data.length, res.pagination.total)
					that.pagination = res.pagination;
					if (page == 1) {
						that.list = res.data
					} else {
						that.list = [...that.list, ...res.data]
					}
					that.pagination.page++
				})
				
			},
			upCallback() {
				this.getData(this.pagination.page)
			},
			downCallback() {
				this.pagination.page = 1;
				this.mescroll.resetUpScroll();
			},
		}
	}
</script>

<style lang="less" scoped>
	.list {
		// width: 700rpx;
		padding: 0 14rpx;
		margin: 0 auto;
		box-shadow: 0 0 40rpx 0 #CCCCCC;
		border-radius: 10rpx;
	
		.list-title {
			display: flex;
			padding: 29rpx 15rpx 0 15rpx;
			box-sizing: border-box;
			align-items: center;
	
			.text {
				flex: 1;
				font-size: 32rpx;
				color: #FD8201;
				font-weight: bold;
			}
	
			.more {
				font-size: 24rpx;
				color: #999;
			}
		}
	
		.tips {
			font-size: 22rpx;
			color: #999;
			padding: 17rpx 15rpx 15rpx 0;
		}
	
		.list-item {
			width: 100%;
			box-sizing: border-box;
	
			.goods {
				width: 100%;
				padding: 40rpx 14rpx;
				border-bottom: 1px solid #eee;
				display: flex;
				justify-content: space-between;
	
				.img {
					margin-right: 30rpx;
	
					image {
						width: 210rpx;
						height: 210rpx;
					}
				}
	
				.content {
					flex: 1;
	
					.title {
						font-size: 26rpx;
						color: #333;
	
						text {
							display: inline-block;
							vertical-align: top;
						}
	
						.num {
							background-color: #353743;
							color: #fff;
							font-size: 20rpx;
							padding: 4rpx 9rpx;
							margin-right: 9rpx;
							margin-top: 3rpx;
						}
					}
	
					.price {
						margin: 24rpx 0;
						display: flex;
						align-items: baseline;
						.now-price {
							color: #FD8201;
							font-size: 34rpx;
							margin-right: 20rpx;
							font-family: SimHei;
						}
	
						.old-price {
							color: #ccc;
							font-size: 20rpx;
							margin-left: 20rpx;
							text-decoration: line-through
						}
					}
	
					.bottom {
						display: flex;
						align-items: center;
	
						.imgs {
							display: flex;
							align-items: center;
							image {
								width: 35rpx;
								height: 35rpx;
								border-radius: 50%;
								margin-right: 15rpx;
							}
	
							image+image {
								margin-left: -12rpx;
							}
						}
	
						.text {
							font-size: 24rpx;
							color: #666;
							flex: 1;
						}
	
						.invite {
							background-color: #FA5B40;
							border-radius: 5rpx;
							padding: 10rpx 10rpx;
							font-size: 20rpx;
							color: #fff;
						}
					}
				}
			}
		}
	}
</style>
